﻿/*
Copyright (C) 2008 raohmaru <http://www.raohmaru.com>

This file is part of Raohmaru AS3 Framework.

Raohmaru AS3 Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Raohmaru AS3 Framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Raohmaru AS3 Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

package jp.raohmaru.form 
{
import jp.raohmaru.utils.ArrayUtil;

/**
 * Utilidades para componentes de formulario.
 * @author raohmaru
 * @version 1.0
 */
public class FormUtil 
{
	/**
	 * Devuelva una matriz con tantos elementos como el rango especificado, siendo cada elemento de la matriz un objeto con los valores <code>label</code> y
	 * <code>value</code> igual al número correspondiente.
	 * @param start Inicio del rango (o fin del rango si no se especifica <code>end</code>).
	 * @param end Fin del rango.
	 * @param decimal Convierte los valores en números de coma flotante y desplaza la coma la cantidad de decimales especificados.
	 * @return Una matriz con el rango especificado.
	 * @example
	 * <listing version="3.0">
	 * import jp.raohmaru.form.FormUtil;
	 * import fl.data.DataProvider;
	 * 
	 * var dp:DataProvider = new DataProvider();
	 * 	dp.addItems(FormUtil.addRangeComboItems(10, 0, 1));
	 * trace(dp.length);  // 11
	 * 
	 * cb.dataProvider = dp;
	 * </listing>
	 */
	public static function getRangeComboItems(start : int, end : int = 0, decimal : int = 0) : Array
	{
		var arr : Array = ArrayUtil.range(start, end, decimal),
			data :Array = [];
		
		for each (var v:Number in arr) {
		   data.push( {label:v, value:v} );
		}
		
		return data;
	}
}
}